

package com.tr.rentcar.controller.houtai.base;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import com.tr.rentcar.model.dao.Websetdao;

@WebServlet("/houtaiwebmessage")
@MultipartConfig(maxFileSize = 10 * 1024 * 1024)
public class WebmessageController extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.getRequestDispatcher("/WEB-INF/jsp/houtai_Webmessage.jsp").forward(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try{
		//String FILE_SAVE_ROOT_PATH = "D:/Users/Administrator/git/rentcar/WebContent/statics/image/upload/companylogo";
		String FILE_SAVE_ROOT_PATH = "F:/git/zjy/rentcar/WebContent/statics/image/upload/companylogo";
		 Part part = req.getPart("tx");
		 String fileName = part.getSubmittedFileName();
		 File uploadDir = new File(FILE_SAVE_ROOT_PATH);
		 if (!uploadDir.exists()) {
				uploadDir.mkdirs();
			}
			String suffix = fileName.substring(fileName.lastIndexOf("."));
			String newFileName = UUID.randomUUID().toString() + suffix;
			String filePath = uploadDir + File.separator + newFileName;
			part.write(filePath);
			String title=req.getParameter("title");
			String key=req.getParameter("key");
			String describe=req.getParameter("describe");
			String comname=req.getParameter("comname");
			String right=req.getParameter("right");
			String introduce=req.getParameter("introduce");
			String tel=req.getParameter("tel");
			new Websetdao().save(title, key, describe, comname, introduce, tel, newFileName);
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		doGet(req, resp);
	}

}
